<?php
namespace app\model;

use app\common\service\redis\PoolRedis;
use think\facade\Log;

/**
 * @mixin \think\Model
 */
class AdminAppRotation extends Base {

    const APP_ROTATION_CACHE_KEY = 'app_rotation:';

    //
    public function school() {
        return $this->belongsTo(AdminSchool::class, 'school_id')
            ->where('is_delete', 0)->bind([
                'school_name' => 'name'
            ]);
    }

    public static function onAfterWrite($model)
    {
        $redis = PoolRedis::instance();
        $keys = PoolRedis::scanAllForMatch(self::APP_ROTATION_CACHE_KEY."*");
        foreach ($keys as $key) {
            $redis->delete($key);
        }
    }
}
